1 // Equipo Poncho, Carriel y Ruana
23 template <class T
> string
toStr(const T
&x
)
24 { stringstream s
; s
<< x
; return s
.str(); }
25 template <class T
> int toInt(const T
&x
)
26 { stringstream s
; s
<< x
; int r
; s
>> r
; return r
; }
28 #define For(i, a, b) for (int i=(a); i<(b); ++i)
29 #define foreach(x, v) for (typeof (v).begin() x = (v).begin(); x != (v).end(); ++x)
30 #define D(x) cout << #x " = " << (x) << endl;
32 const double EPS
= 1e-9;
34 int cmp(double x
, double y
= 0, double tol
= EPS
) {
35 return (x
<= y
+ tol
) ? (x
+ tol
< y
) ? -1 : 0 : 1;
40 #define MAXBUFF (1<<18)
41 char buffer
[MAXBUFF
], *p
= buffer
+MAXBUFF
;
42 char buffer2
[MAXBUFF
], *p2
= buffer2
;
44 inline char read_char() {
45 if( p
== buffer
+MAXBUFF
) {
46 fread( buffer
, 1, MAXBUFF
, stdin
);
52 inline int read_int() {
54 while( !isdigit(c
= read_char()) );
56 while( isdigit(c
= read_char()) ) ret
= ret
* 10 + c
-'0';
61 fwrite( buffer2
, 1, p2
-buffer2
, stdout
);
65 inline void write( char c
) {
66 if( p2
== buffer2
+MAXBUFF
) {
67 fwrite( buffer2
, 1, MAXBUFF
, stdout
);
76 const int MAXBASES
= 105, oo
= 1 << 28;
80 int dp
[MAXBASES
][1 << 16];
85 for (int i
= 0; i
< 16; ++i
){
86 printf("%d", !!(x
& (1 << i
)));
91 for (int i
= 0; i
<= B
; ++i
) {
92 for (int mask
= 0; mask
< (1 << 16); ++mask
) {
98 for (int i
= 0; i
< B
; ++i
) {
99 for (int mask
= 0; mask
< (1 << 16); ++mask
) {
100 if (dp
[i
][mask
] >= oo
) continue;
103 dp
[i
+1][mask
] = min(dp
[i
+1][mask
], dp
[i
][mask
]);
104 dp
[i
+1][mask
| base
] = min(dp
[i
+1][mask
| base
], dp
[i
][mask
] + 1);
113 if (B
== 0 and D
== 0) break;
114 for (int i
= 0; i
< B
; ++i
) {
117 int k
= IO::read_int();
119 int x
= IO::read_int(); x
--;
120 bases
[i
] |= (1 << x
);
124 for (int j
= 0; j
< D
; ++j
) {
126 int k
= IO::read_int();
128 int x
= IO::read_int(); x
--;
132 int ans
= dp
[B
][doc
];
133 if (ans
>= oo
) ans
= 0;
136 if (j
+ 1 < D
) printf(" ");